
<script>
  import fetch from '@/utils/fetch';
  import {Tree} from 'element-ui';
  import {list2tree} from '@/utils/treeUtils';

  delete Tree.props.data;

  export default {
    data(){
      return {
        data:[]
      }
    },
    mixins: [Tree],
    props:{
      defaultProps:{
        default(){
          return {
            children: 'children',
            label: 'label'
          };
        }
      },
      filterNode:{
        type:Function
      }
    },
    created() {
      const _this = this;
      httpClient.default(() => fetch({
        url: '/gi-paas-sd-sqlcomputesvc/api/service/querySql',
        method: 'put',
        data: {
          'position': 'projectStructure_queryProjectTree',
          'paramMap': {},
        },
      }), function(error, result) {
        if(_this.filterNode){
          result = result.filter(item=>_this.filterNode(item));
        }
        result.forEach(item=>{
          if(item.parentId){
            //分期楼栋
            item.lable = item.name;
          }else{
            //项目
            item.lable = item.projectName;
          }
        });
        _this.data = list2tree(result);
      })
    },
  };

</script>
